/**
 * Created by leezhenbo on 15/5/21.
 */
package {
import flash.display.Bitmap;
import flash.utils.Dictionary;

import starling.textures.Texture;
import starling.textures.TextureAtlas;

public class Assets {

    [Embed(source="../media/graphics/mySpritesheet.png")]
    public static const AtlasTextureGame:Class;

    [Embed(source="../media/graphics/mySpritesheet.xml",mimeType="application/octet-stream")]
    public static const AtlasXMLGame:Class;

    //背景图片
    [Embed(source="../media/graphics/bgLayer1.jpg")]
    public static const BgLayer1:Class;
    //欢迎界面
    [Embed(source="../media/graphics/bgWelcome.jpg")]
    public static const BgWelcome:Class;

    //cache
    private static var gameTextures:Dictionary = new Dictionary(true);
    private static var gameTextureAtlas:TextureAtlas;

    public function Assets() {

    }

    /**
     * 根据图片名称生成纹理图片
     * @param name
     * @return Bitmap
     */
    public static function getTexture(name:String):Texture{
        if(gameTextures[name] == undefined){
            var bitmap:Bitmap = new Assets[name]();
            gameTextures[name] = Texture.fromBitmap(bitmap);
        }
        return gameTextures[name];
    }

    /**
     *
     * @return
     */
    public static function getTextureAtlas():TextureAtlas{
        if(gameTextureAtlas == null){
            var texture:Texture = getTexture("AtlasTextureGame");
            var xml:XML = XML(new AtlasXMLGame());
            gameTextureAtlas = new TextureAtlas(texture,xml);
        }
        return gameTextureAtlas;
    }
}
}
